package com.byzk.p2p.admin.borrow.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.borrow.dao.GuaranteeDao;
import com.byzk.p2p.admin.borrow.dto.Guarantee;

/**
 *	担保方Service
 */
@Service
public class GuaranteeService {
	@Autowired
	private GuaranteeDao guaranteeDao;

	/**
	 * 根据ID查询
	 */
	public Guarantee getById(Integer id) {
		return guaranteeDao.getById(id);
	}

	/**
	 * 删除
	 */
	public boolean delete(Integer id) {
		return guaranteeDao.delete(id) > 0 ? true : false;
	}

	/**
	 * 保存或修改
	 */
	public boolean saveOrUpdate(Guarantee guarantee) {
		if (guarantee == null)
			return false;
		if (guarantee.getId() == null) {
			return guaranteeDao.insert(guarantee) > 0 ? true : false;
		}
		return guaranteeDao.update(guarantee) > 0 ? true : false;
	}

	/**
	 * 获取分页信息
	 */
	public PageInfo<Guarantee> getPageInfo(Map<String, Object> param, int index, int limit) {
		if (param == null) {
			param = new HashMap<String, Object>();
		}
		param.put("start", (index - 1) * limit);
		param.put("limit", limit);
		int count = guaranteeDao.countByParam(param);
		List<Guarantee> list = guaranteeDao.listByParam(param);
		PageInfo<Guarantee> pageInfo = new PageInfo<Guarantee>(count, index, limit);
		pageInfo.setPageList(list);
		return pageInfo;
	}
	
	/**
	 * 获取全部担保公司
	 */
	public List<Guarantee> listAll(){
		return guaranteeDao.listAll();
	}
}
